package com.longqin.wechat.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.longqin.wechat.entity.AccessToken;
import com.longqin.wechat.service.UserService;

/**
 * @Description: 账号控制器
 * @Author longqin
 * @Date 2025-05-07
 * 
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Resource
	private UserService userService;
	
	/**微信授权,返回用户微信信息，同时返回是否已经绑定的结果
	 * @param code
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/wxAuthorization",produces={"application/json;charset=UTF-8"})
	public AccessToken authorization(@RequestParam String code) throws Exception{
		return userService.authorization(code);
	}
	
	/**登录
	 * @param userName 账号
	 * @param password 密码
	 * @param openId 微信唯一标识
	 * @return
	 * @throws Exception
	 */
	@PostMapping(value="/wxLogin")
	public AccessToken login(@RequestParam String userLogin,@RequestParam String password,@RequestParam String openId) throws Exception{
		return userService.login(userLogin, password, openId);
	}
	
	/**刷新token
     * @param refresh_token 用于刷新token
     * @return
     * @throws Exception
     */
    @GetMapping("/refreshToken")
    public AccessToken refreshToken(@RequestParam String publicrefresh_token) throws Exception {
    	return userService.refreshToken(publicrefresh_token);
    }
	
	/**
	 * @Description: 退出登录，解除账号和微信的绑定
	 * @param openId
	 * @return
	 * @throws Exception
	 * @Author longqin
	 * @Date 2025-05-07
	 * 
	 */
    @PostMapping(value="/wxLogout")
	public boolean wxLogout(@RequestParam String openId) throws Exception{
		return userService.wxLogout(openId);
	}
	
}
